package com.johann.aboutdate;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateDiff {
    public static void main(String[] args) {
        String dateString = "2022-01-06";
        System.out.println(judgeLoop(dateString));
    }

    private static int judgeLoop(String dateString){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        //获取当前时间
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        long nowTime =  cal.getTimeInMillis();
        System.out.println(nowTime);
        //解析输入的时间
        try {
            cal.setTime(sdf.parse(dateString));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long earlyTime = cal.getTimeInMillis();
        long diff = (nowTime-earlyTime)/(1000*3600*24);
        return Integer.parseInt(String.valueOf(diff));
    }


}
